from selenium import webdriver  #用于操作浏览器
from selenium.webdriver.chrome.options import Options #用于设置谷歌浏览器
from selenium.webdriver.chrome.service import Service #用于管理驱动
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.common.alert import Alert

Login= ["fujipeng",123456,]
#设置浏览器/启动浏览器
def she():
    #创建设置浏览器对象
    hycx = Options()
    #禁用浏览器沙盒模式
    hycx.add_argument('--no-sandbox')
    #保持浏览器的打开状态
    hycx.add_experimental_option('detach',True)
    #创建并启动浏览器
    a1 = webdriver.Chrome(service=Service('../chromedriver.exe'), options=hycx)
    return a1
a1 = she()
a1.get('http://8.147.105.44:3001/login?redirect=%2Findex')
time.sleep(2)
a1.maximize_window()
#定位账号元素
a2=a1.find_element(By.XPATH,'//*[@id="app"]/div[1]/form/div[1]/div/div[1]/input')
#输入账号
a2.send_keys(Login[0])
#定位密码元素
time.sleep(1)
a3=a1.find_element(By.XPATH,'//*[@id="app"]/div[1]/form/div[2]/div/div[1]/input')
#输入密码
a3.send_keys(Login[1])
#定位登录按钮元素
time.sleep(1)
#定位个人隐私协议
a5 = a1.find_element(By.XPATH,'//*[@id="app"]/div[1]/form/div[3]/div/label/span[1]/span').click()
time.sleep(2)
a4=a1.find_element(By.XPATH,'//*[@id="app"]/div[1]/form/div[4]/div/button/span/span').click()
time.sleep(5)
#点击登录



#进入订单管理
a6=a1.find_element(By.XPATH,'//*[@id="app"]/div[1]/div[1]/div[2]/div[1]/div/ul/div[3]/li/div').click()
time.sleep(2)
#进入单票寄件
a7=a1.find_element(By.XPATH,'//*[@id="app"]/div[1]/div[1]/div[2]/div[1]/div/ul/div[3]/li/ul/div[2]/a/li').click()
time.sleep(2)



#a=a1.find_element(By.XPATH,'')
fjr = [
    "zhangyangang","ningxia","yinchuan","xixiaqu","zhangsan",
    8618095485395,750021,"8618095485555","xixiaqubeij"
       ]
#发件人信息：姓名
a8=a1.find_element(By.XPATH,'//*[@id="app"]/div[1]/div[2]/section/div/form/div[1]/div[1]/div[2]/div[1]/div/div[1]/input')
a8.send_keys(fjr[0])
#国家
a9=a1.find_element(By.XPATH,'//*[@id="app"]/div[1]/div[2]/section/div/form/div[1]/div[1]/div[2]/div[2]/div/div/div/span/span/i').click()
time.sleep(2)
a10=a1.find_element(By.XPATH,'/html/body/div[2]/div[1]/div[1]/ul/li').click()
#省州
a11=a1.find_element(By.XPATH,'//*[@id="app"]/div[1]/div[2]/section/div/form/div[1]/div[1]/div[2]/div[3]/div/div/input')
a11.send_keys(fjr[1])
#城市
a11=a1.find_element(By.XPATH,'//*[@id="app"]/div[1]/div[2]/section/div/form/div[1]/div[1]/div[2]/div[4]/div/div/input')
a11.send_keys(fjr[2])
#县区
a11=a1.find_element(By.XPATH,'//*[@id="app"]/div[1]/div[2]/section/div/form/div[1]/div[1]/div[2]/div[5]/div/div[1]/input')
a11.send_keys(fjr[3])
#联系人
a11=a1.find_element(By.XPATH,'//*[@id="app"]/div[1]/div[2]/section/div/form/div[1]/div[1]/div[2]/div[6]/div/div[1]/input')
a11.send_keys(fjr[4])
#移动电话
a11=a1.find_element(By.XPATH,'//*[@id="app"]/div[1]/div[2]/section/div/form/div[1]/div[1]/div[2]/div[7]/div/div[1]/input')
a11.send_keys(fjr[5])
#邮编
a11=a1.find_element(By.XPATH,'//*[@id="app"]/div[1]/div[2]/section/div/form/div[1]/div[1]/div[2]/div[8]/div/div[1]/input')
a11.send_keys(fjr[6])
#电话
a11=a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[1]/div[1]/div[2]/div[9]/div/div[1]/input')
a11.send_keys(fjr[7])
#详细地址
a11=a1.find_element(By.XPATH,'//*[@id="app"]/div[1]/div[2]/section/div/form/div[1]/div[1]/div[2]/div[10]/div/div[1]/textarea')
a11.send_keys(fjr[8])


sjr = [
    "lichanghong","henansheng","zhoukou","xixiaqu","zhangsan",
    8618095485395,90001,8618095485555,"xixiaqubeij"
]
#收件人信息
#发件人信息：姓名
a8=a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[1]/div[2]/div[2]/div[1]/div/div[1]/input')
a8.send_keys(sjr[0])
#国家
b1=a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[1]/div[2]/div[2]/div[2]/div/div/div/span/span/i').click()
time.sleep(2)
b2=a1.find_element(By.XPATH,'/html/body/div[3]/div[1]/div[1]/ul/li').click()
#省州
b3=a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[1]/div[2]/div[2]/div[3]/div/div[1]/input')
b3.send_keys(sjr[1])
#城市
b4=a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[1]/div[2]/div[2]/div[4]/div/div[1]/input')
b4.send_keys(sjr[2])
#县区
b5=a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[1]/div[2]/div[2]/div[5]/div/div[1]/input')
b5.send_keys(sjr[3])
#联系人
b6=a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[1]/div[2]/div[2]/div[6]/div/div[1]/input')
b6.send_keys(sjr[4])
#移动电话
b7=a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[1]/div[2]/div[2]/div[7]/div/div[1]/input')
b7.send_keys(sjr[5])
#邮编
b8=a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[1]/div[2]/div[2]/div[8]/div/div[1]/input')
b8.send_keys(sjr[6])
#电话
b9=a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[1]/div[2]/div[2]/div[9]/div/div[1]/input')
b9.send_keys(sjr[7])
#详细地址
b10=a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[1]/div[2]/div[2]/div[10]/div/div[1]/textarea')
b10.send_keys(sjr[8])
time.sleep(2)


#包裹信息
#邮件体积
c1 = a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[2]/div[2]/div[1]/div/div[1]/input')
c1.clear()
time.sleep(3)
c1.send_keys('50')
#邮费
c2 = a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[2]/div[2]/div[2]/div/div/input')
c2.clear()
time.sleep(3)
c2.send_keys('500')
#运输产品
c3=a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[2]/div[2]/div[6]/div/div/div/span/span/i').click()
time.sleep(5)
c4=a1.find_element(By.XPATH,'/html/body/div[4]/div[1]/div[1]/ul/li[1]').click()
#邮件重量
c5=a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[2]/div[2]/div[7]/div/div/input')
c5.clear()
time.sleep(3)
c5.send_keys('500')
#长
c6=a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[2]/div[2]/div[8]/div/div/input')
c6.clear()
time.sleep(3)
c6.send_keys('48')
#宽
c7=a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[2]/div[2]/div[9]/div/div/input')
c7.clear()
time.sleep(3)
c7.send_keys('48')
#高
c8=a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[2]/div[2]/div[10]/div/div/input')
c8.clear()
time.sleep(3)
c8.send_keys('48')


#浏览器滚动到底部
a1.execute_script("window.scrollTo(0, document.body.scrollHeight);")


#商品信息中文
d1 = a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[3]/div[2]/div[1]/div[2]/div/div[1]/input')
d1.send_keys('小米手机')
#商品信息英文
d2 = a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[3]/div[2]/div[1]/div[3]/div/div[1]/input')
d2.send_keys('miphone')
#商品类型名称中文
d3 = a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[3]/div[2]/div[1]/div[4]/div/div[1]/input')
d3.send_keys('手机')
#商品类型名称英文
d4 = a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[3]/div[2]/div[1]/div[5]/div/div[1]/input')
d4.send_keys('phone')
#商品数量
d5 = a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[3]/div[2]/div[1]/div[6]/div/div/input')
d5.clear()
time.sleep(3)
d5.send_keys('10')
#商品单价
d6 = a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[3]/div[2]/div[1]/div[7]/div/div/input')
d6.clear()
time.sleep(1)
d6.send_keys('5')
#申报价值
d7 = a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[3]/div[2]/div[1]/div[8]/div/div/input')
d7.clear()
time.sleep(1)
d7.send_keys('5')
#商品重量
d8 = a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[3]/div[2]/div[1]/div[10]/div/div/input')
d8.clear()
time.sleep(1)
d8.send_keys('10')
#商品描述
d9 = a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[3]/div[2]/div[1]/div[11]/div/div[1]/input')
d9.send_keys('电子元件')
#商品单位
d10 = a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/form/div[3]/div[2]/div[1]/div[12]/div/div[1]/input')
d10.send_keys('个')


#提交下单
e1 = a1.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[2]/section/div/div/button[1]').click()

